/*
 * @Description: 
 * @Autor: 商晓彬
 * @Date: 2021-07-28 14:00:11
 * @LastEditors: 商晓彬
 * @LastEditTime: 2021-12-06 11:10:12
 */
import { Component, EventEmitter, Injector, Input, Output, ViewChild } from '@angular/core';
import { AppComponentBase } from '@shared/common/app-component-base';
import { ProcessRouteServiceProxy, CommonServiceProxy } from '@shared/service-proxies/service-proxies';
import { ModalDirective } from 'ngx-bootstrap';
import * as _ from 'lodash';
import { finalize } from 'rxjs/operators';
import { MessageService } from '@abp/message/message.service';
import { Table } from 'primeng/components/table/table';
import { Paginator } from 'primeng/components/paginator/paginator';
import { LazyLoadEvent } from 'primeng/components/common/lazyloadevent';
import { HttpClient } from '@angular/common/http';

@Component({
    selector: 'importBop',
    templateUrl: './import-bop.component.html',
    styleUrls: ['./import-bop.component.less']
})
export class ImportBopComponent extends AppComponentBase {
    //引入子组件
    @ViewChild('createOrEditModal') modal: ModalDirective;
    @ViewChild('dataTable') dataTable: Table;
    @ViewChild('paginator') paginator: Paginator;
    @Output() modalSave: EventEmitter<any> = new EventEmitter<any>();
    @Input() parentrow: any;//当前点击节点
    @Input() bopInfo: any;//当前bopInfo
    saving = false;
    active = false;
    selectedCar: any;
    model = { label: undefined, value: undefined };
    modelList = [];
    lotNo = { label: undefined, value: undefined };
    lotNoList = [];
    drawingNo = undefined;
    constructor(
        injector: Injector,
        private _processRouteServiceProxy: ProcessRouteServiceProxy,
        private _messageService: MessageService,
        private _commonServiceProxy: CommonServiceProxy,
        private _httpClient: HttpClient
    ) {
        super(injector);
        // this.filterText = this._bopContentServiceProxy.snapshot.queryParams['filterText'] || '';
    }
    ngOnInit() {
    }
    //导入工艺规程
    show(): void {
        this.active = true;
        this.modal.show();
        //型号
        this._commonServiceProxy.getModelList(
        )
            .pipe(finalize(() => { })).subscribe(result => {
                this.modelList = result;
            })
       
    }
    onChange(event) {
         //发次
        this._commonServiceProxy.getLotNoList(
             this.model.value
            )
                .pipe(finalize(() => { })).subscribe(result => {
                    this.lotNoList = result;
                })
    }
    //关闭事件
    close(): void {
        this.active = false;
        this.selectedCar = undefined;
        this.modal.hide();
    }
    getProcessDraw(event?: LazyLoadEvent) {
        let that = this;
        setTimeout(() => {
            if (that.primengTableHelper.shouldResetPaging(event)) {
                that.paginator.changePage(0);
                return;
            }
            that.primengTableHelper.showLoadingIndicator();
            that._processRouteServiceProxy.getProcessRoute(
                undefined,
                this.model.label,
                this.lotNo.label,
                undefined,
                this.model.value,
                this.lotNo.value,
                this.drawingNo,
                undefined,
                3,
                undefined,
                undefined,
                this.bopInfo.id
            ).pipe(finalize(() => that.primengTableHelper.hideLoadingIndicator())).subscribe(result => {
                that.primengTableHelper.records = result;
                that.primengTableHelper.hideLoadingIndicator();
            });
        }, 10);
    }
    resetSearch() {
        this.model.label = undefined;
        this.model.value = undefined;
        this.lotNo.label = undefined;
        this.lotNo.value = undefined;
        this.drawingNo = undefined;
    }
    save() {
        if (!this.selectedCar) {
            this._messageService.info('请选择一条数据');
            return;
        }
        abp.ui.setBusy(undefined, '', 1);
        this._processRouteServiceProxy.transferProcessData(
            this.selectedCar.id,
            this.bopInfo.id
        )
            .pipe(finalize(() => { this.saving = false; }))
            .subscribe(result => {
                this._messageService.success('引入BOP成功');
                abp.ui.clearBusy();
                this.close();
                this.modalSave.emit(null);
            });
    }
}
